home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / p2c4os2.zip / DISTRIB / OS2 / P2C.DOC < prev    next >
Text File  |  1992-08-01  |  52KB  |  1,452 lines

  1.  
  2.  
  3.  
  4.      P2C(1)               (local)            P2C(1)
  5.  
  6.  
  7.  
  8.      NAME
  9.       p2c -    Pascal to C translator,    version    1.19
  10.  
  11.      SYNOPSIS
  12.       p2c [    options    ] [ file [ module ] ]
  13.  
  14.      DESCRIPTION
  15.       P2c is a tool    for translating    Pascal programs    into C.     The
  16.       input    consists of a set of source files in any of the
  17.       following Pascal dialects: HP    Pascal,    Turbo/UCSD Pascal, DEC
  18.       VAX Pascal, Oregon Software Pascal/2,    Macintosh Programmer's
  19.       Workshop Pascal, Sun/Berkeley    Pascal.     Modula-2 syntax is
  20.       also supported.  Output is a set of .c and .h    files that
  21.       comprise an equivalent program in any    of several dialects of
  22.       C.  Output code may be kept machine- and dialect-
  23.       independent, or it may be targeted to    a specific machine and
  24.       compiler.  Most reasonable Pascal programs are converted
  25.       into fully functional    C which    will compile and run with no
  26.       further modifications, although p2c sometimes    chooses    to
  27.       generate readable code at the    expense    of absolute
  28.       generality. P2c endeavors to insert notes and    warning
  29.       messages into    the output code    to point out areas which may
  30.       require human    intervention.  Output code is arranged to be
  31.       readable and efficient, and to make use of C idioms wherever
  32.       possible.  The main goal of the translation is to produce C
  33.       files    which are pleasant and "natural" enough    to be
  34.       acceptable as    the new    source files for a program.  In    a
  35.       pinch, p2c will also serve as    an ad hoc Pascal compiler.
  36.  
  37.       Code generated by p2c    normally does not assume characters
  38.       are signed or    unsigned.  Also, it assumes int    is the same as
  39.       either short or long but does    not depend on which.  However,
  40.       if int is not    the same as long it is best to use a modern C
  41.       compiler which supports prototypes.  Generated code does not
  42.       require an ANSI-compatible compiler (unless ANSI-style code
  43.       is requested), but it    does use various ANSI-standard library
  44.       routines.
  45.  
  46.       All generated    code includes the file <p2c/p2c.h> which in
  47.       turn includes    <stdio.h> and various other common resources.
  48.       Also,    many translated    programs will need to be linked    with
  49.       the run-time library,    typically -lp2c.
  50.  
  51.       Given    a file name, p2c reads from the    specified file and
  52.       outputs to a file with a .c suffix added or substituted.
  53.       For example,
  54.  
  55.            p2c myfile.pas
  56.  
  57.       reads    from myfile.pas    to produce the file myfile.c. The
  58.       input    file may contain a Pascal main program or a single
  59.       Pascal module    (or "unit" in Turbo and    UCSD Pascal
  60.  
  61.  
  62.  
  63.                    - 1 - Formatted:  February 28, 1991
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.      P2C(1)               (local)            P2C(1)
  71.  
  72.  
  73.  
  74.       nomenclature), or it may just    contain    a number of procedures
  75.       and declarations.  P2c is designed to    work for correct input
  76.       programs.  That is, it will accept partial programs but may
  77.       occasionally core dump if the    input refers to    undefined
  78.       symbols.
  79.  
  80.       If the input is a module, the    translator will    also produce a
  81.       file module.h    containing a translation of the    module's
  82.       interface section.  The implementation section may be
  83.       omitted in which case    only the .h file will be interesting.
  84.       If the program or module has include files, these may    cause
  85.       additional .c    files to be generated depending    on the value
  86.       of the ExpandIncludes    option (see below).
  87.  
  88.       If no    file name is given, p2c    reads Pascal from the standard
  89.       input    and writes the resulting C to standard output (though
  90.       a .h file may    still be produced).  If    a file name and    module
  91.       name are given, the file may include several modules (or
  92.       units).  The specified module    is translated; any others are
  93.       skipped.  The    output files will be named module.c and
  94.       module.h.  P2c never translates more than one    module per
  95.       run.
  96.  
  97.       Before starting, p2c reads the file /usr/lib/p2c/p2crc for a
  98.       number of configuration parameters.  (The actual path    used
  99.       on your system may vary.  The    -i option is a handy way to
  100.       examine this file.) If the P2CRC environment variable    is
  101.       set, it gives    the name of a file to read instead of the
  102.       system file; this file can start with    Include    %H/p2crc to
  103.       include the system file.  Next, p2c attempts to read the
  104.       file p2crc in    your directory for further configuration.  If
  105.       this file does not exist, p2c    looks for .p2crc instead.
  106.  
  107.      OPTIONS
  108.       -o cfile
  109.            Use cfile in place of file.c or module.c    as the primary
  110.            output file.  A single dash (`-o    -') says to write the
  111.            C code to the standard output.
  112.  
  113.       -h hfile
  114.            Use hfile in place of module.h as the output file for
  115.            interface text.    This only has effect if    the input is
  116.            an HP Pascal module or a    Turbo Pascal unit.
  117.  
  118.       -s sfile
  119.            Read interface text from    sfile before beginning the
  120.            translation.  This file typically contains one or more
  121.            modules,    often with interface sections omitted for
  122.            speed, which the    program    or module being    translated
  123.            will use.  (Typically the ImportFrom and    ImportDir
  124.            parameters in p2crc are set up to allow p2c to locate
  125.            interface text without needing any -s options.)    If
  126.  
  127.  
  128.  
  129.                    - 2 - Formatted:  February 28, 1991
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.      P2C(1)               (local)            P2C(1)
  137.  
  138.  
  139.  
  140.            there are several -s options in the command, the    sfiles
  141.            are read    from left to right.
  142.  
  143.       -pn  Display progress    of translation in the form of a    line
  144.            number/file name    display.  This is refreshed every n
  145.            lines, 25 by default.
  146.  
  147.       -c rcfile
  148.            Read local configuration    commands from rcfile instead
  149.            of p2crc    or .p2crc. A dash (`-c -') in place of rcfile
  150.            causes no local configuration file to be    used.
  151.  
  152.       -v   ("Vanilla.")  Do    not read from the system configuration
  153.            file /usr/lib/p2c/p2crc.    Since some of the parameters
  154.            in this file are    required, your local configuration
  155.            file must include those parameters instead.  This also
  156.            suppresses the file named by the    P2CRC environment
  157.            variable.
  158.  
  159.       -H homedir
  160.            Use homedir instead of /usr/lib/p2c as the p2c home
  161.            directory.  The system p2crc file will be searched for
  162.            in this directory.
  163.  
  164.       -Ipattern
  165.            Add pattern to the ImportDir search list    of places to
  166.            find modules which are imported.     The pattern should
  167.            include a %s to represent the module name, and should
  168.            evaluate    to a potential file name for that module's
  169.            source code.  For example, ../%s.pas looks for
  170.            modulename.pas in the parent of the current directory.
  171.  
  172.       -i   This special option (which must be the only argument on
  173.            the command line    if used) simply    copies the system
  174.            configuration file /usr/lib/p2c/p2crc to    the standard
  175.            output in its entirety.    (It may    be used    with -H, but
  176.            -i is most useful precisely when    you don't know the
  177.            location    of the home directory.)
  178.  
  179.       -q   Quiet mode.  Suppresses output of status    messages
  180.            during translation.
  181.  
  182.       -En  Abort translation after n errors.  If n is omitted it
  183.            defaults    to zero, which means unlimited errors are
  184.            allowed.     Use -E1 to make p2c halt after    the first
  185.            error.
  186.  
  187.       -e   Echo the    Pascal source into the output file, surrounded
  188.            by #ifdefs.  This is the    same as    the CopySource
  189.            parameter in the    p2crc file.
  190.  
  191.       -a   Produce modern ANSI C.  This is a convenient override
  192.  
  193.  
  194.  
  195.                    - 3 - Formatted:  February 28, 1991
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.      P2C(1)               (local)            P2C(1)
  203.  
  204.  
  205.  
  206.            for the AnsiC parameter in the p2crc file.
  207.  
  208.       -L language
  209.            Select input language name, such    as VAX or TURBO.  This
  210.            is a convenient override    for the    Language parameter.
  211.  
  212.       -V   Verbose mode.  This causes p2c to generate an
  213.            additional ".log" file with further details of the
  214.            translation, such as a list of warnings and notes
  215.            including those which are suppressed in the regular
  216.            output.
  217.  
  218.       -M0  Disable memory conservation.  This prevents p2c from
  219.            freeing various data structures after translating each
  220.            function, in case this new conservation feature causes
  221.            unforseen problems.
  222.  
  223.       -R   Regression testing mode.     Formats notes and warning
  224.            messages    in a way that makes it easier to run diff(1)
  225.            on the output of    p2c.
  226.  
  227.       P2c also understands a few debugging options which may
  228.       occasionally be useful when tracking down translation
  229.       problems.  The -dn option sets the "debug level" to n, a
  230.       small    integer    which is normally zero.     Debugging output is
  231.       written into the regular output file along with the C    code;
  232.       the higher your n, the more "wallpaper" you get.  Also, -t
  233.       prints debugging information at every    Pascal token, -Bn
  234.       enables line-breaker debugging, and -Cn enables comment
  235.       placement debugging.
  236.  
  237.      CHOICE OF SOURCE LANGUAGE
  238.       The Language configuration parameter or -L command-line
  239.       option tells p2c which Pascal    dialect    to expect in the input
  240.       file.     Any language features which do    not overlap between
  241.       dialects are supported all of    the time.  The Language
  242.       parameter is consulted when a    syntax or usage    is detected
  243.       that has different meanings in two different dialects, and
  244.       also to determine default values for various other
  245.       translation parameters as described below.
  246.  
  247.       The following    language words are supported by    p2c. Names are
  248.       case-insensitive.
  249.  
  250.       HP      HP Pascal.  This is the default language.  All
  251.           features of HP Standard Pascal, the Pascal
  252.           Workstation version, are supported except as noted
  253.           in BUGS below.  Some features    of MODCAL, HP's
  254.           extended Pascal, are also supported.    This is    a
  255.           superset of ISO standard Pascal, including
  256.           conformant arrays and    procedural parameters.
  257.  
  258.  
  259.  
  260.  
  261.                    - 4 - Formatted:  February 28, 1991
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.      P2C(1)               (local)            P2C(1)
  269.  
  270.  
  271.  
  272.       HP-UX      HP Pascal, HP-UX version.  Almost identical to the
  273.           "HP" dialect.
  274.  
  275.       Turbo      Turbo    Pascal 5.0 for the IBM PC.  Few    conflicts with
  276.           HP Pascal, so    the Language parameter is not often
  277.           needed for Turbo.  (Most important is    that the Turbo
  278.           and HP dialects use 16 and 32    bit integers,
  279.           respectively.)
  280.  
  281.       UCSD      UCSD Pascal.    Similar    to Turbo in many ways.
  282.  
  283.       MPW      Macintosh Programmer's Workshop Pascal 2.0.  Should
  284.           also do a pretty good    job for    Lightspeed Pascal.
  285.           Object Pascal    features are not supported, nor    is the
  286.           fact that char variables are sometimes stored    in 16
  287.           bits.
  288.  
  289.       VAX      VAX/VMS Pascal version 3.5.  Most but    not all
  290.           language features supported.    This has not yet been
  291.           tested on large programs.
  292.  
  293.       Oregon  Oregon Software Pascal/2.  All features implemented.
  294.  
  295.       Berk      Berkeley Pascal with Sun extensions.
  296.  
  297.       Modula  Modula-2.  Based on Wirth's Programming in Modula-2,
  298.           3rd edition.    Proper setting of the Language
  299.           parameter is not optional.  Translation will be
  300.           incomplete in    most cases, but    should be good enough
  301.           to work with.     Structure of local sub-modules    is
  302.           essentially ignored; like-named identifiers may be
  303.           confused.  Type WORD is translated as    an integer,
  304.           but type ADDRESS is translated as char * or void *;
  305.           this may cause inconsistencies in the    output code.
  306.  
  307.           Modula-2 modules have    two parts in separate files.
  308.           Suppose these    are called foo.def (definition part)
  309.           and foo.mod (implementation part) for    module foo.
  310.           Then a pattern like %s.def must be included in the
  311.           ImportDir list, and LibraryFile must be changed to
  312.           refer    to system.m2 instead of    system.imp. To
  313.           translate the    definition part, give the command
  314.  
  315.                p2c foo.def
  316.  
  317.           to translate the definition part into    files foo.h
  318.           and foo.c; the latter    will usually be    empty.    The
  319.           command
  320.  
  321.                p2c -s foo.def foo.mod
  322.  
  323.           will translate the implementation part into file
  324.  
  325.  
  326.  
  327.                    - 5 - Formatted:  February 28, 1991
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.      P2C(1)               (local)            P2C(1)
  335.  
  336.  
  337.  
  338.           foo.c.
  339.  
  340.       Even if all language features    are supported for a dialect,
  341.       some predefined functions may    be omitted.  In    these cases,
  342.       the function call will be translated literally into C    with a
  343.       warning.  Some hand modification may be required.
  344.  
  345.      CONFIGURATION PARAMETERS
  346.       P2c is highly    configurable.  The defaults are    suitable for
  347.       most applications, but customizing these parameters will
  348.       help you get the best    possible translation.  Since the
  349.       output of p2c    is intended to be used as human-maintainable
  350.       source code, there are many parameters for describing    the
  351.       coding style and conventions you prefer.  Others give    hints
  352.       about    your program that help p2c to generate more correct,
  353.       efficient, or    readable code.
  354.  
  355.       The p2crc files contain a list of parameters,    one per    line.
  356.       The system configuration file, which may be viewed using the
  357.       -i option to p2c, serves as an example of the    proper format.
  358.       Parameter names are case-insensitive.     If a parameter    name
  359.       occurs exactly once in the system p2crc, this    indicates that
  360.       it must have a unique    value and the last value given to it
  361.       by the configuration files is    used.  Other parameters    are
  362.       written several times    in a row; these    are lists to which
  363.       each configuration line adds an entry.
  364.  
  365.       Many p2crc options take a numeric value of 0 or 1, roughly
  366.       corresponding    to "no"    or "yes."  Sometimes a blank value or
  367.       the value "def" corresponds to an intermediate "maybe"
  368.       state.  For example, the stylistic option ExtraParens
  369.       switches between copious or minimal parentheses in
  370.       expressions, with the    default    being a    nice compromise
  371.       intended to be best for readers with an average knowledge of
  372.       C operator precedences.
  373.  
  374.       Configuration    options    may also be embedded in    the source
  375.       file in the form of Pascal comments:
  376.  
  377.            {ShortOpt=0} {AvoidName=fred}
  378.            {FuncMacro slope(x,y)=atan2(y,x)*RadDeg}
  379.  
  380.       disables automatic short-circuiting of and and or
  381.       expressions, adds "fred" to the list of names    to avoid using
  382.       in generated C code, and defines a special translation for
  383.       the Pascal program's slope function using the    standard C
  384.       atan2    function and a constant    RadDeg presumably defined in
  385.       the program.    Whitespace is generally    not allowed in
  386.       embedded parameters.    The `='    sign is    required for embedded
  387.       parameters, though it    is optional in p2crc files.  Comments
  388.       within embedded parameters are delimited by `##'.  Numeric
  389.       parameters may replace `=' with `+' or `-' to    increase or
  390.  
  391.  
  392.  
  393.                    - 6 - Formatted:  February 28, 1991
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.      P2C(1)               (local)            P2C(1)
  401.  
  402.  
  403.  
  404.       decrease the parameter; list-based parameters    may use    `-' to
  405.       remove a name    from a list rather than    adding it.  Also, the
  406.       parameter name by itself in comment braces means to restore
  407.       the parameter's value    that was current before    the last
  408.       change:
  409.  
  410.            {VarFiles=0  ## Pass FILE *'s params by value even if
  411.       VAR}
  412.            some declarations
  413.            {VarFiles    ## Back to original    FILE * passing}
  414.  
  415.       causes the parameter VarFiles    to have    the value 0 for    those
  416.       few declarations, without affecting the parameter's value
  417.       elsewhere in the file.
  418.  
  419.       If an    embedded parameter appears in an include file or in
  420.       interface text for a module, the effect of the assignment
  421.       normally carries over    to any programs    that included that
  422.       file.     If the    parameter name is preceded by a    `*', then the
  423.       assignment is    automatically undone after the source file
  424.       that contains    it ends:
  425.  
  426.            {IncludeFrom strings=<p2c/strings.h>}
  427.            {*ExportSymbol=pascal_%s}
  428.            module strings;
  429.  
  430.       will record the location of the strings module's include
  431.       file for the rest of the translation,    but the    assignment of
  432.       ExportSymbol pertains    only to    the module itself.
  433.  
  434.       For the complete list    of p2crc parameters, run p2c with the
  435.       -i option.  Here are some additional comments    on selected
  436.       parameters:
  437.  
  438.       ImportAll     Because Turbo Pascal only allows one unit per
  439.              source    file, p2c normally stops reading past
  440.              the word implementation in a file being
  441.              scanned for interface text.  But HP Pascal
  442.              allows    several    modules    per file and so    this
  443.              would not be safe to do.  The ImportAll
  444.              option    lets you override the default behavior
  445.              for your Pascal dialect.
  446.  
  447.       AnsiC         This parameter    selects    which dialect of C to
  448.              use.  If 1, all conventions of    ANSI C such as
  449.              prototypes, void * pointers, etc. are used.
  450.              If 0, only strict K&R (first edition) C is
  451.              used.    The default is to use "traditional
  452.              UNIX C," which    includes enum and void but not
  453.              void *    or prototypes.    Once again there are a
  454.              number    of other parameters which may be used
  455.              to control the    individual features if just
  456.  
  457.  
  458.  
  459.                    - 7 - Formatted:  February 28, 1991
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.      P2C(1)               (local)            P2C(1)
  467.  
  468.  
  469.  
  470.              setting AnsiC is not enough.
  471.  
  472.       C++         At present p2c    does not use much of C++ at
  473.              all.  The default action is to    generate code
  474.              that will compile in either language.
  475.  
  476.       UseVExtern     Many non-UNIX linkers prohibit    variables from
  477.              being defined (not declared) by more than one
  478.              source    file.  One module must declare,    e.g.,
  479.              "int foo;", and all others must declare
  480.              "extern int foo;".  P2c accomplishes this by
  481.              declaring public variables "vextern" in
  482.              header    files, and arranging for the macro
  483.              vextern to expand to extern or    to nothing
  484.              when appropriate.  If you set UseVExtern=0
  485.              p2c will instead declare variables in a
  486.              simpler way that works    only on    UNIX-style
  487.              linkers.
  488.  
  489.       UseAnyptrMacros
  490.              Certain C reserved words have meanings    which
  491.              may vary from one C implementation to
  492.              another.  P2c uses special capitalized    names
  493.              for these words; these    names are defined as
  494.              macros    in the file p2c.h which    all translated
  495.              programs include.  You    can set
  496.              UseAnyptrMacros=0 to disable the use of these
  497.              macros.  Note that the    functions of many of
  498.              these macros can also be had directly using
  499.              other parameters; for example,    UseConsts
  500.              allows    you to specify whether your target
  501.              language recognizes the word const in
  502.              constant declarations.     The default is    to use
  503.              the Const macro instead, so that your code
  504.              will be portable to either kind of
  505.              implementation.
  506.  
  507.              Signed    expands    to the reserved    word signed if
  508.              that word is available, otherwise it is given
  509.              a null    definition.  Similarly,    Const expands
  510.              to const if that feature is available.     The
  511.              words Volatile    and Register are also defined
  512.              in p2c.h, although p2c    does not use them at
  513.              present.  The word Char expands to char by
  514.              default, but might need to be redefined to
  515.              signed    char or    unsigned char in a particular
  516.              implementation.  This is used for the Pascal
  517.              character type; lowercase char    is used    when
  518.              the desired meaning is    "byte,"    not
  519.              "character."
  520.  
  521.              The word Static always    expands    to static by
  522.  
  523.  
  524.  
  525.                    - 8 - Formatted:  February 28, 1991
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.      P2C(1)               (local)            P2C(1)
  533.  
  534.  
  535.  
  536.              default.  This    is used    in situations where a
  537.              function or variable is declared static to
  538.              make it local to the source file; lowercase
  539.              static    is used    for static local variables.
  540.              Thus you can redefine Static to be null if
  541.              you want to force private names to be public
  542.              for purposes of debugging.
  543.  
  544.              The word Void expands to void in all cases;
  545.              it is used when declaring a function with no
  546.              return    value.    The word Anyptr    is a typedef
  547.              for void * or char * as necessary; it
  548.              represents a generic pointer.
  549.  
  550.       UsePPMacros     The p2c.h header also declares    two macros for
  551.              function prototyping, PP(x) and PV().    These
  552.              macros    are used as follows:
  553.  
  554.                   Void foo    PP( (int x, int    y, Char    *z) );
  555.                   Char *bar    PV( );
  556.  
  557.              If prototypes are available, these macros
  558.              will expand to
  559.  
  560.                   Void foo    (int x,    int y, Char *z);
  561.                   Char *bar    (void);
  562.  
  563.              but if    only old-style declarations are
  564.              supported, you    instead    get
  565.  
  566.                   Void foo    ();
  567.                   Char *bar    ();
  568.  
  569.              By default, p2c uses these macros for all
  570.              function declarations,    but function
  571.              definitions are written in old-style C.  The
  572.              UsePPMacros parameter can be set to 0 to
  573.              disable all use of PP and PV, or it can be
  574.              set to    1 to use the macros even when defining
  575.              a function.  (This is accomplished by
  576.              preceding each    old-style definition with a
  577.              PP-style declaration.)     If you    know your code
  578.              will always be    compiled on systems that
  579.              support prototyping, it is prettier to    set
  580.              Prototypes=1 or simply    AnsiC=1    to get true
  581.              function prototypes.
  582.  
  583.       EatNotes     Notes and warning messages containing any of
  584.              these strings as sub-strings are not omitted.
  585.              Each type of message includes an identifier
  586.              like [145]; you can add this identifier to
  587.              the EatNotes list to suppress that message.
  588.  
  589.  
  590.  
  591.                    - 9 - Formatted:  February 28, 1991
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.      P2C(1)               (local)            P2C(1)
  599.  
  600.  
  601.  
  602.              Another useful    form is    to use a variable name
  603.              or other identifier to    suppress warnings
  604.              about that variable.  The strings are a
  605.              space-separated list, and thus    may not
  606.              contain embedded spaces.  To suppress notes
  607.              around    a section of code, use,    e.g.,
  608.              {EatNotes+[145]} and {EatNotes-[145]}.    Most
  609.              notes are generated during parsing, but to
  610.              suppress those    generated during output    the
  611.              string    may need to remain in the list far
  612.              beyond    the point where    it appears to be
  613.              generated.  Use the string "1"    or "0" to
  614.              disable or enable all notes, respectively.
  615.  
  616.       ExpandIncludes The default action is to expand Pascal
  617.              include files in-line.     This may not be
  618.              desirable if include files are    being used to
  619.              simulate modules.  With ExpandIncludes=0, p2c
  620.              attempts to convert include files containing
  621.              only whole procedures and global declarations
  622.              into analogous    C include files.  This may not
  623.              always    work, though; if you get error
  624.              messages, don't use this option.  By
  625.              combining this    option with StaticFunctions=0,
  626.              then doing some fairly    minor editing on the
  627.              result, you can convert a pseudo-modular
  628.              Pascal    program    into a truly modular
  629.              collection of C source    files.
  630.  
  631.       ElimDeadCode     Some transformations that p2c does on the
  632.              program may result in unreachable or "dead"
  633.              code.    By default p2c removes such code, but
  634.              sometimes it removes more than    it should.  If
  635.              you have "if false" segments which you    wish
  636.              to retain in C, you may have to set
  637.              ElimDeadCode=0.
  638.  
  639.       SkipIndices     Normally Pascal arrays    not based at zero are
  640.              "shifted" down    for C, preserving the total
  641.              size of the array.  A Pascal array a[2..10]
  642.              is translated to a C array a[9] with
  643.              references like "a[i]"    changed    to "a[i-2]"
  644.              everywhere.  If SkipIndices is    set to a value
  645.              of 2 or higher, this array would instead be
  646.              translated to a[11] with the first two
  647.              elements never    used.  This arrangement    may
  648.              generate incorrect code, though, for tricky
  649.              source    programs.
  650.  
  651.       FoldConstants     Pascal    non-structured constants generally
  652.              translate to #define's    in C.  Set this    to 1
  653.              to have constants instantiated    directly into
  654.  
  655.  
  656.  
  657.                   - 10 - Formatted:  February 28, 1991
  658.  
  659.  
  660.  
  661.  
  662.  
  663.  
  664.      P2C(1)               (local)            P2C(1)
  665.  
  666.  
  667.  
  668.              the code.  This may be    turned on or off
  669.              around    specific constant declarations.     Set
  670.              this to 0 to force p2c    to make    absolutely no
  671.              assumptions about the constant's value    in
  672.              generated code, so that you can change    the
  673.              constant later    in the C code without
  674.              invalidating the translation.    The default is
  675.              to allow p2c to take advantage    of its
  676.              knowledge of a    constant's value, such as by
  677.              generating code that assumes the constant is
  678.              positive.
  679.  
  680.       CharConsts     This governs whether single-character string
  681.              literals in Pascal const declarations should
  682.              be interpreted    as characters or strings.  In
  683.              other words, const a='x'; will    translate to
  684.              #define a 'x' if CharConsts=1 (the default),
  685.              or to #define a x if CharConsts=0.  Note that
  686.              if p2c    guesses    wrong, the generated code will
  687.              not be    wrong, just uglier.  For example, if a
  688.              is written as a character constant but    it
  689.              turns out to be used as a string, p2c will
  690.              have to write char-to-string conversion code
  691.              each time the constant    is used.
  692.  
  693.       VarStrings     In HP Pascal, a parameter of the form "var s
  694.              : string" will    match a    string variable    of any
  695.              size; a hidden    size parameter is passed which
  696.              may be    accessed by the    Pascal strmax
  697.              function.  You    can prevent p2c    from creating
  698.              a hidden size parameter by setting
  699.              VarString=0.  (Note that each function    uses
  700.              the value of VarStrings as of the first
  701.              declaration of    the function that is parsed,
  702.              which is often    in the interface section of a
  703.              module.)
  704.  
  705.       Prototypes     Control whether ANSI C    function prototypes
  706.              are used.  Default is according to AnsiC.
  707.              This also controls whether to include
  708.              parameter names or just their types in
  709.              situations where names    are optional.  The
  710.              FullPrototyping parameter allows prototypes
  711.              to be generated for declarations but not for
  712.              definitions (older versions of    Lightspeed C
  713.              required this).  If you use a mixture of
  714.              prototypes and    old-style definitions, types
  715.              like short and    float will be promoted to int
  716.              and double as required    by the ANSI standard,
  717.              unless    PromoteArgs is used to override    this.
  718.              The CastArgs parameter    controls whether
  719.              type-casts are    used in    function arguments; by
  720.  
  721.  
  722.  
  723.                   - 11 - Formatted:  February 28, 1991
  724.  
  725.  
  726.  
  727.  
  728.  
  729.  
  730.      P2C(1)               (local)            P2C(1)
  731.  
  732.  
  733.  
  734.              default they are used only if prototypes are
  735.              not available.
  736.  
  737.       StaticLinks     HP Pascal and Turbo Pascal each include the
  738.              concept of procedure or function pointers,
  739.              though    with somewhat different    syntaxes.  P2c
  740.              recognizes both notational styles.  Another
  741.              difference is that HP's procedure pointers
  742.              can point to nested procedures, while Turbo's
  743.              can point only    to global procedures.  In HP
  744.              Pascal    a procedure pointer must be stored as
  745.              a struct containing both a pure C function
  746.              pointer and a "static link," a    pointer    to the
  747.              parent    procedure's locals.  (The static link
  748.              is NULL for global procedures.)  This
  749.              notation can be forced    by setting
  750.              StaticLinks=1.     In Turbo, the default
  751.              (StaticLinks=0) is to use plain C function
  752.              pointers with no static links.     A third
  753.              option    (StaticLinks=2)    uses structures    with
  754.              static    links, but assumes the links are
  755.              always    NULL when calling through a pointer
  756.              (if you need compatibility with the HP    format
  757.              but know your procedures are global).
  758.  
  759.       SmallSetConst     Pascal    sets are translated into one of    two
  760.              formats, depending on the size    of the set.
  761.              If all    elements have ordinal values in    the
  762.              range 0..31, the set is translated as a
  763.              single    integer    variable using bit operations.
  764.              (The SetBits parameter    may be used to change
  765.              the upper limit of 31.) The SmallSetConst
  766.              parameter controls whether these small-sets
  767.              are used, and,    if so, how constant sets
  768.              should    be represented in C.   For larger
  769.              sets, an array    of long    is used.  The s[0]
  770.              element contains the number of    succeeding
  771.              array elements    which are in use.  Set
  772.              elements in the range 0..31 are stored    in the
  773.              s[1] array element, and so on.     Sets are
  774.              normalized so that s[s[0]] is nonzero for any
  775.              nonempty set.    The standard run-time library
  776.              includes all the necessary procedures for
  777.              operating on sets.
  778.  
  779.       ReturnValueName
  780.              This is one of    many "naming conventions"
  781.              parameters.  Most of these take the form of a
  782.              printf-like string containing a %s where the
  783.              relevant information should go.  In the case
  784.              of ReturnValueName, the %s refers to a
  785.              function name and the resulting string    gives
  786.  
  787.  
  788.  
  789.                   - 12 - Formatted:  February 28, 1991
  790.  
  791.  
  792.  
  793.  
  794.  
  795.  
  796.      P2C(1)               (local)            P2C(1)
  797.  
  798.  
  799.  
  800.              the name of the variable to use to hold the
  801.              function's return value.  Such    a variable
  802.              will be made if a function contains
  803.              assignments to    its return value buried    within
  804.              the body, so that return statements cannot
  805.              conveniently be used.    Some parameters
  806.              (ReturnValueName included) do not require the
  807.              %s to be present in the format    string;    for
  808.              example, the standard p2crc file stores every
  809.              function's return value in a variable called
  810.              Result.
  811.  
  812.       AlternateName     P2c normally translates Pascal    names into C
  813.              names verbatim, but occasionally this is not
  814.              possible.  A Pascal name may be a C reserved
  815.              word or traditional C name like putc, or
  816.              there may be several like-named things    that
  817.              are hidden from each other by Pascal's
  818.              scoping rules but must    be global in C.     In
  819.              these situations p2c uses the parameter
  820.              AlternateName1    to generate an alternative
  821.              name for the symbol.  The default is to add
  822.              an underscore to the name.  There is also an
  823.              AlternateName2    parameter for a    second
  824.              alternate name, and an    AlternateName
  825.              parameter for the nth alternate name.    (The
  826.              value for this    parameter should include both
  827.              a %s and a %d,    in either order.)  If these
  828.              latter    parameters are not defined, p2c
  829.              applies AlternateName1    many times over.
  830.  
  831.       ExportSymbol     Symbols in the    interface section for a    Pascal
  832.              module    are formatted according    to the value
  833.              of ExportSymbol, if any.  It is not uncommon
  834.              to use    modulename_%s for this symbol; the
  835.              default is %s,    i.e., no special treatment for
  836.              exported symbols.  If you also    define the
  837.              Export_Symbol parameter, that format is used
  838.              instead for exported symbols which contain an
  839.              underscore character.    If %S (with a capital
  840.              "S") appears in the format string it stands
  841.              for the current module    name.
  842.  
  843.       Alias         If the    value of this parameter    contains a %s,
  844.              it is a format    string applied to the names of
  845.              external functions or variables.  If the
  846.              value does not    contain    a %s, it becomes the
  847.              name of the next external symbol which    is
  848.              declared (after which the parameter is
  849.              cleared).
  850.  
  851.       Synonym     This creates a    synonym    for another Pascal
  852.  
  853.  
  854.  
  855.                   - 13 - Formatted:  February 28, 1991
  856.  
  857.  
  858.  
  859.  
  860.  
  861.  
  862.      P2C(1)               (local)            P2C(1)
  863.  
  864.  
  865.  
  866.              symbol    or keyword.  The format    is
  867.  
  868.                   Synonym old-name = new-name
  869.  
  870.              All occurrences of old-name in    the input text
  871.              are treated as    if they    were new-name by the
  872.              parser.  If new-name is a keyword, old-name
  873.              will be an equivalent keyword.     If new-name
  874.              is the    name of    a predefined function, old-
  875.              name will behave in the same way as that
  876.              function, and so on.  If new-name is omitted,
  877.              then occurrences of old-name are entirely
  878.              ignored in the    input file.  Synonyms allow
  879.              you to    skip over a keyword in your dialect of
  880.              Pascal    that is    not understood by p2c, or to
  881.              simulate a keyword or predefined identifier
  882.              of your dialect with a    similar    one that p2c
  883.              recognizes.  Note that    all predefined
  884.              functions are available at all    times; if you
  885.              have a    library    routine    that behaves like,
  886.              e.g., Turbo Pascal's getmem procedure,    you
  887.              can make your routine a synonym for getmem
  888.              even if you are not translating in Turbo
  889.              mode.
  890.  
  891.       NameOf     This defines the name to use in C for a
  892.              specific symbol.  It must appear before the
  893.              symbol    is declared in the Pascal code;    it is
  894.              usually placed    in the local p2crc file    for
  895.              the project.  The format is
  896.  
  897.                   NameOf pascal-name = C-name
  898.  
  899.              By default, Pascal names map directly onto C
  900.              names with no change (except for the various
  901.              kinds of formatting outlined above).  If the
  902.              pascal-name is    of the form module.name    or
  903.              procedure.name    then the command applies only
  904.              to the    instance of the    Pascal name that is
  905.              global    to that    module,    or local to that
  906.              procedure.  Otherwise,    it applies to all
  907.              usages    of the name.
  908.  
  909.       VarMacro     This is analogous to NameOf, but specifically
  910.              for use with Pascal variables.     The righthand
  911.              side can be most any C    expression; all
  912.              references to the variable are    expanded into
  913.              that C    expression.  Names used    in the C
  914.              expression are    taken verbatim.     There is also
  915.              a ConstMacro parameter    for translating
  916.              constants as arbitrary    expressions.  Note
  917.              that the variable on the lefthand side    must
  918.  
  919.  
  920.  
  921.                   - 14 - Formatted:  February 28, 1991
  922.  
  923.  
  924.  
  925.  
  926.  
  927.  
  928.      P2C(1)               (local)            P2C(1)
  929.  
  930.  
  931.  
  932.              actually be declared in the program or    in a
  933.              module    that it    uses.  The declaration for the
  934.              variable will be omitted from the generated
  935.              code unless the Pascal-name appears in    the
  936.              expression:  If you ask to replace i with
  937.              i+1, the variable i will still    be declared
  938.              but its value will be shifted accordingly.
  939.              Note that if i    appears    on the lefthand    side
  940.              of an assignment, p2c will use    algebra    to
  941.              "solve" for i.
  942.  
  943.              In all    cases where p2c    parses C expressions,
  944.              all C operators are recognized    except
  945.              compound assignments like `+='.  (Increment
  946.              and decrement operators are allowed.) All
  947.              variable and function names are assumed to
  948.              have integer type, even if they are names
  949.              that occur in the actual program.  A type-
  950.              specification operator    `::' has been
  951.              introduced; it    has the    same precedence    as `.'
  952.              or `->' but the righthand side    must be    a
  953.              Pascal    type identifier    (built-in or defined
  954.              by your program previously to when the    macro
  955.              definition was    parsed), or an arbitrary
  956.              Pascal    type expression    in parentheses.     The
  957.              lefthand argument is then considered to have
  958.              the specified type.  This may be necessary if
  959.              your macro is used in situations where    the
  960.              exact type of the expression must be known
  961.              (say, as the argument to a writeln).
  962.  
  963.       FieldMacro     Here the lefthand side    must have the form
  964.              record.field, where record is the Pascal type
  965.              or variable name for a    record,    and field is a
  966.              field in that record.    The righthand side
  967.              must be a C expression    generally including
  968.              the name record. All instances    of that    name
  969.              are replaced by the actual record being
  970.              "dotted." For example,
  971.  
  972.                   FieldMacro Rect.topLeft =    topLeft(Rect)
  973.  
  974.              translates a[i].topLeft into topLeft(a[i]),
  975.              where a is an array of    Rect.
  976.  
  977.       FuncMacro     The lefthand side must    be any Pascal function
  978.              or procedure name plus    a parameter list.  The
  979.              number    of parameters must match the number in
  980.              the function's    uses and declaration.  Calls
  981.              to the    function are replaced by the C
  982.              expression on the righthand side.  For
  983.              example,
  984.  
  985.  
  986.  
  987.                   - 15 - Formatted:  February 28, 1991
  988.  
  989.  
  990.  
  991.  
  992.  
  993.  
  994.      P2C(1)               (local)            P2C(1)
  995.  
  996.  
  997.  
  998.                   FuncMacro    PtInRect(p,r) =    PtInRect(p,&r)
  999.  
  1000.              causes    the second argument of PtInRect    to be
  1001.              passed    by reference, even though the
  1002.              declaration says it's not.  If    the function
  1003.              in question is    actually defined in the
  1004.              program or module being translated, the
  1005.              FuncMacro will    not affect the definition but
  1006.              it will affect    all calls to the function
  1007.              elsewhere in the module.  FuncMacros can also
  1008.              be applied to predefined or never-defined
  1009.              functions.
  1010.  
  1011.       IncludeFrom     This specifies    that a given module's header
  1012.              should    be included from a given place.     The
  1013.              second    argument may be    surrounded by "    " or
  1014.              < > as    necessary; if the second argument is
  1015.              omitted, no include directive will be
  1016.              generated for the module.
  1017.  
  1018.       ImportFrom     This specifies    that a given module's Pascal
  1019.              interface text    can be found in    the given
  1020.              file.    The named file should be either    the
  1021.              source    file for the module, or    a specially
  1022.              prepared file with the    implementation section
  1023.              removed for speed.  If    no ImportFrom entry is
  1024.              found for a module, the path defined by the
  1025.              ImportDir list    is searched.  Each entry in
  1026.              the path may contain a    %s, which expands to
  1027.              the name of the module.  The default path
  1028.              looks for %s.pas and %s.text in the current
  1029.              directory, then for /usr/lib/p2c/%s.imp.
  1030.              (where    /usr/lib/p2c is    the p2c    home
  1031.              directory.)
  1032.  
  1033.       StructFunction This parameter    is a list of functions which
  1034.              follow    the p2c    semantics for structure-valued
  1035.              functions (functions returning    arrays,    sets,
  1036.              and strings, and structs in primitive C
  1037.              dialects).  For these functions, a pointer to
  1038.              a return-value    area is    passed to the function
  1039.              as a special first parameter.    The function
  1040.              stores    the result in this area, then returns
  1041.              a copy    of the pointer.     (The standard C
  1042.              function strcpy is an example of this
  1043.              concept.  Sprintf also    behaves    this way in
  1044.              some dialects;    it always appears on the
  1045.              StructFunction    list regardless    of the type of
  1046.              implementation.)  The system configuration
  1047.              file includes a list of common    structured
  1048.              functions so that p2c's optimizer will    know
  1049.              how to    manipulate them.
  1050.  
  1051.  
  1052.  
  1053.                   - 16 - Formatted:  February 28, 1991
  1054.  
  1055.  
  1056.  
  1057.  
  1058.  
  1059.  
  1060.      P2C(1)               (local)            P2C(1)
  1061.  
  1062.  
  1063.  
  1064.       StrlapFunction Functions on this list    are structured
  1065.              functions as above, but with the ability to
  1066.              work in-place;    that is, the same pointer may
  1067.              be passed as both the return value area and a
  1068.              regular parameter.
  1069.  
  1070.       Deterministic     Functions on this list    have no    side effects
  1071.              or side dependencies.    An example is the sin
  1072.              function in the standard math library;    two
  1073.              calls with the    same parameter values produce
  1074.              the same result, and have no effects other
  1075.              than returning    a value.  P2c can make use of
  1076.              this knowledge    when optimizing    code for
  1077.              efficiency or readability.  Functions on this
  1078.              list are also assumed to be relatively    fast,
  1079.              so that it is acceptable to duplicate a call
  1080.              to the    function.
  1081.  
  1082.       LeaveAlone     Functions on this list    are not    subjected to
  1083.              the normal built-in translation rules that
  1084.              p2c would otherwise use.  For example,    adding
  1085.              writeln to this list would translate writeln
  1086.              statements blindly into calls to a C
  1087.              writeln() function, rather than being
  1088.              translated into equivalent printf calls.  The
  1089.              built-in translation is also suppressed if
  1090.              the function has a FuncMacro.
  1091.  
  1092.       BufferedFile     P2c normally assumes binary files will    use
  1093.              read/write, not get/put/^ notation.  A    file
  1094.              buffer    variable will only be created for a
  1095.              file if buffer    notation is used for it.  For
  1096.              global    file variables this may    be detected
  1097.              too late (a declaration without buffers may
  1098.              already have been written).  Such files can
  1099.              be listed in BufferedFile to force p2c    to
  1100.              allocate buffers for them; do this if you get
  1101.              a warning message that    says it    is necessary.
  1102.              Set BufferedFile=1 to buffer all files, in
  1103.              which case UnBufferedFile allows you to force
  1104.              certain files not to have buffers.
  1105.  
  1106.       StructFiles     If p2c    still can't translate your file
  1107.              operations correctly, you can set
  1108.              StructFiles=1 to cause    Pascal files to
  1109.              translate into    structs    which include the
  1110.              usual C FILE pointer, as well as file buffer
  1111.              and file name fields.    While the resulting
  1112.              code doesn't look as much like    native C, the
  1113.              file structs will allow p2c to    do a correct
  1114.              translation in    many more cases.
  1115.  
  1116.  
  1117.  
  1118.  
  1119.                   - 17 - Formatted:  February 28, 1991
  1120.  
  1121.  
  1122.  
  1123.  
  1124.  
  1125.  
  1126.      P2C(1)               (local)            P2C(1)
  1127.  
  1128.  
  1129.  
  1130.       CheckFileEOF     Normally only file-open operations are
  1131.              checked for errors.  Additional error
  1132.              checking, such    as read-past-end-of-file, can
  1133.              be enabled with parameters like CheckFileEOF.
  1134.              These checks can make the code    very ugly!  If
  1135.              I/O checking is enabled by the    program
  1136.              ($iocheck on$ in HP Pascal; {$I+} in Turbo;
  1137.              this is always    the default state), these
  1138.              checks    will generate fatal errors unless
  1139.              enclosed in an    HP Pascal try-recover
  1140.              construct.  If    I/O checking is    disabled,
  1141.              these will cause the global variable
  1142.              P_ioresult to be set zero or nonzero
  1143.              according to the outcome.  The    default    for
  1144.              most of these options is to check only    when
  1145.              I/O checking is disabled.
  1146.  
  1147.      ISSUES
  1148.       Integer size.    P2c normally generates code to work with
  1149.       either 16 or 32 bit ints.  If    you know your C    integers will
  1150.       be 16    or 32 bits, set    IntSize    appropriately.    In particular
  1151.       setting IntSize=32 will generate much    cleaner    code: p2c no
  1152.       longer must carefully    cast function arguments    between    int
  1153.       and long.  These casts also will be unnecessary if ANSI
  1154.       prototypes are available.  To    disable    int/long casting
  1155.       because you know at least one    of these cases will hold, set
  1156.       CastLongArgs=0.  (The    CastArgs parameter similarly controls
  1157.       other    types of casts,    such as    between    ints and doubles.) The
  1158.       Integer16 parameter controls whether Pascal integers are
  1159.       interpreted as 16 or 32 bits,    or translated as native    C
  1160.       integers.  The default value depends on the Language
  1161.       selected.
  1162.  
  1163.       Signed/unsigned chars. Pascal    characters are normally
  1164.       "weakly" interpreted as unsigned; this is controlled by
  1165.       UnsignedChar.     The default is    "either," so that C's native
  1166.       char type may    be used    even if    its signed-ness    is unknown.
  1167.       Code that uses characters outside of the range 0-127 may
  1168.       need a different setting.  Alternatively, you    can use    the
  1169.       types    {SIGNED} char and {UNSIGNED} char in the few cases
  1170.       where    it really matters.  These comments are controlled by
  1171.       the SignedComment and    UnsignedComment    parameters.  (The type
  1172.       {UNSIGNED} integer is    also recognized.)  The SignedChar
  1173.       parameter tells whether C characters are signed or unsigned
  1174.       (default is "unknown").  The HasSignedChar parameter tells
  1175.       whether the phrase "signed char" is legal in the output.  If
  1176.       it is    not, p2c may have to translate Pascal signed bytes
  1177.       into C shorts.
  1178.  
  1179.       Special types. P2c understands the following predefined
  1180.       Pascal type names: integer, signed integers depending    on
  1181.       Integer16; longint, signed 32-bit integers; unsigned,
  1182.  
  1183.  
  1184.  
  1185.                   - 18 - Formatted:  February 28, 1991
  1186.  
  1187.  
  1188.  
  1189.  
  1190.  
  1191.  
  1192.      P2C(1)               (local)            P2C(1)
  1193.  
  1194.  
  1195.  
  1196.       unsigned 32-bit integers; sword, signed 16-bit integers;
  1197.       word,    unsigned 16-bit    integers; c_int, signed    native C
  1198.       integers; c_uint, unsigned native C integers;    sbyte, signed
  1199.       8-bit    integers; byte,    unsigned 8-bit integers; real,
  1200.       floating-point numbers depending on DoubleReals; single,
  1201.       single-precision floats; longreal, double, and extended,
  1202.       double-precision floats; pointer and anyptr, generic
  1203.       pointers (assignment-compatible with any pointer type);
  1204.       string, generic string of length StringDefault (normally
  1205.       255);    also, the usual    Pascal types char, boolean, and    text.
  1206.       (If your Pascal uses different names for these concepts, the
  1207.       Synonym option will come in handy.)
  1208.  
  1209.       Embedded code. It is possible    to write a Pascal comment
  1210.       containing C code to be embedded into    the output.  See the
  1211.       descriptions of EmbedComment and its relatives in the    system
  1212.       p2crc    file.  These techniques    are helpful if you plan    to do
  1213.       repeated translations    of code    that is    still being maintained
  1214.       in Pascal.
  1215.  
  1216.       Comments and blank lines. P2c    collects the comments in a
  1217.       procedure into a list.  All comments and statements are
  1218.       stamped with serial numbers which are    used to    reattach
  1219.       comments to statements even after code has been added,
  1220.       removed, or rearranged during    translation.  "Orphan"
  1221.       comments attached to statements that have been lost are
  1222.       attached to nearby statements    or emitted at the end of the
  1223.       procedure.  Blank lines are treated as a kind    of comment, so
  1224.       p2c will also    reproduce your usage of    blank lines.  If the
  1225.       comment mechanism goes awry, you can disable comments    with
  1226.       EatComments or disable their being attached to code with
  1227.       SpitComments.
  1228.  
  1229.       Indentation. P2c has a number    of parameters to govern
  1230.       indentation of code.    The default values produce the GNU
  1231.       Emacs    standard indentation style, although p2c can do    a
  1232.       better job since it knows more about the code    it is
  1233.       indenting.  Indentation works    by applying "indentation
  1234.       deltas," which are either absolute numbers (which override
  1235.       the previous indentation), or    signed relative    numbers    (which
  1236.       augment the previous indentation).  A    delta of "+0"
  1237.       specifies no change in indentation.  All of the indentation
  1238.       options are described    in the standard    p2crc file.
  1239.  
  1240.       Line breaking. P2c uses an algorithm similar to the TeX
  1241.       typesetter's paragraph formatter for breaking    long
  1242.       statements into multiple lines.  A "penalty" is assigned to
  1243.       various undesirable aspects of all possible line breaks; the
  1244.       "badness" of a set of    line breaks is approximately the sum
  1245.       of all the penalties.     Chief among these are serious
  1246.       penalties for    overrunning the    desired    maximum    line length
  1247.       (default 78 columns),    an infinite penalty for    overrunning
  1248.  
  1249.  
  1250.  
  1251.                   - 19 - Formatted:  February 28, 1991
  1252.  
  1253.  
  1254.  
  1255.  
  1256.  
  1257.  
  1258.      P2C(1)               (local)            P2C(1)
  1259.  
  1260.  
  1261.  
  1262.       the absolute maximum line length (default 90), and
  1263.       progressively    greater    penalties for breaking at operators
  1264.       deeply nested    in expressions.     Parameters such as
  1265.       OpBreakPenalty control the relative weights of various
  1266.       choices.  BreakArith and its neighbors control whether the
  1267.       operator at a    line break should be placed at the end of the
  1268.       previous line    or at the beginning of the next.  If you don't
  1269.       want any oversize lines, define MaxLineWidth=78.
  1270.  
  1271.       Unlike TeX, p2c's line breaker must actually try all
  1272.       possible sets    of break points.  To avoid excessive
  1273.       computation, the total penalty contributed at    each decision
  1274.       point    must sum to a nonnegative value; negative values are
  1275.       clipped up to    zero.  This allows p2c to prune    away obviously
  1276.       undesirable alternatives in advance.    The MaxLineBreakTries
  1277.       parameter (default 5000) controls how    many alternatives to
  1278.       try before giving up and using the best so far.
  1279.  
  1280.       PASCAL_MAIN. P2c generates a call to this function at    the
  1281.       front    of the main program.  In the (unmodified) run-time
  1282.       library all this does    is save    argc and argv away because in
  1283.       both HP and Turbo these are accessed as global variables.
  1284.       If you do not    wish to    use this feature, define ArgCName to
  1285.       be argc, ArgVName to be argv,    and MainName (normally
  1286.       "PASCAL_MAIN") to be blank.  This will work if argc and argv
  1287.       are never accessed outside of    your main program.
  1288.  
  1289.      BUGS
  1290.       P2c was designed with    the idea that clean, readable output
  1291.       in most cases    is worth more than guaranteed correct output
  1292.       in extreme cases.  P2c is not    a compiler!  However, ideally
  1293.       the "extreme"    cases would include only those which never
  1294.       arise    in real    life.  Thus if p2c actually generates
  1295.       incorrect code I will    consider it a bug, but I will not
  1296.       apologize for    it. :-)     Below are the major remaining cases
  1297.       where    this is    known to occur.
  1298.  
  1299.       Certain kinds    of conformant array parameters (including
  1300.       multi-dimensional conformant arrays) produce code that
  1301.       declares variable-length arrays in C.     Only a    few C
  1302.       compilers, such as the GNU C compiler, support this language
  1303.       extension.  Otherwise    some hand re-coding will be required.
  1304.  
  1305.       HP Pascal try-recover    structures are translated into calls
  1306.       to TRY and RECOVER macros, which are defined to simulate the
  1307.       construct using setjmp and longjmp. If this emulation    does
  1308.       not work, define the symbol FAKE_TRY to cause    these macros
  1309.       to become "inert."  (In cases    where the error    is detected by
  1310.       code physically within the body of the try statement,    a C
  1311.       goto to the recover section is always    generated.)  Also,
  1312.       local    file variables in scopes which are destroyed by    an
  1313.       escape are not closed.
  1314.  
  1315.  
  1316.  
  1317.                   - 20 - Formatted:  February 28, 1991
  1318.  
  1319.  
  1320.  
  1321.  
  1322.  
  1323.  
  1324.      P2C(1)               (local)            P2C(1)
  1325.  
  1326.  
  1327.  
  1328.       Non-local GOTO's and try-recover statements are each
  1329.       implemented, but may conflict    if both    are used at once.
  1330.       Non-local GOTO's are fairly careful about closing files that
  1331.       go out of scope but may fail to do so    in the presence    of
  1332.       recursion.
  1333.  
  1334.       Arrays containing files are not initialized to NULL as other
  1335.       files    are.  In some cases, such as file variables allocated
  1336.       by NEW, the file is initialized but not automatically    closed
  1337.       by DISPOSE.
  1338.  
  1339.       LINK variables allowing sub-procedures access    to their
  1340.       parents' variables are occasionally omitted by mistake, if
  1341.       the access is    too indirect for p2c to    notice.     If this
  1342.       happens, you can add an explicit reference to    a parent
  1343.       variable in the sub-procedure.  A statement of the form
  1344.       "a:=a" will count as a reference but then be optimized away
  1345.       by p2c.
  1346.  
  1347.       Many aspects of Modula-2 are translated only superficially.
  1348.       For example, the type-compatibility properties of the    WORD
  1349.       and ARRAY OF WORD types are only roughly modelled, as    are
  1350.       the scope rules concerning modules.
  1351.  
  1352.       Parts    of VAX Pascal are still    untreated.  In particular, the
  1353.       [UNSAFE] attribute and a few others are not fully supported,
  1354.       nor are the semantics    of the OPEN procedure.
  1355.  
  1356.       Turbo    and VAX    Pascal's double, quadruple, and    extended real
  1357.       types    all translate to the C double type.  Turbo's
  1358.       computational    type is    not supported at all.
  1359.  
  1360.       Because Pascal strings (with length bytes) are translated
  1361.       into C strings (with null terminators), certain Pascal
  1362.       string tricks    will not work in the translated    code.  For
  1363.       example the assignment s[0]:=chr(x) is translated to s[x]=0
  1364.       on the assumption that the string is being shortened.     If x
  1365.       is actually greater than the current length, but not of a
  1366.       recognizable form like ord(s[0])+n, then the generated code
  1367.       will not work.  In VAX Pascal    this corresponds to performing
  1368.       arithmetic on    the LENGTH field of a varying-length string.
  1369.  
  1370.       Turbo    Pascal's automatic clipping of strings is not
  1371.       supported.  In Turbo,    if a ten character string is assigned
  1372.       to a string[8] variable, the last two    characters are
  1373.       silently removed.  The code produced by p2c generally    will
  1374.       overrun the target string instead!  The StringTruncLimit
  1375.       parameter (80    by default if Language=Turbo) specifies    a
  1376.       string size which should be considered "short"; assignments
  1377.       of potentially-long strings to short string variables    will
  1378.       cause    a warning but will not automatically truncate.    The
  1379.       cure is to use copy in the Pascal source to truncate the
  1380.  
  1381.  
  1382.  
  1383.                   - 21 - Formatted:  February 28, 1991
  1384.  
  1385.  
  1386.  
  1387.  
  1388.  
  1389.  
  1390.      P2C(1)               (local)            P2C(1)
  1391.  
  1392.  
  1393.  
  1394.       strings explicitly.
  1395.  
  1396.      FILES
  1397.       file.xxx         Pascal    source files
  1398.       file.c         resulting C source file
  1399.       module.h         resulting C header file
  1400.       p2crc             local configuration file
  1401.       .p2crc         alternate local configuration file
  1402.       /usr/lib/p2c/p2crc     system-wide configuration file
  1403.       /usr/lib/p2c/system.impdeclarations for predefined functions
  1404.       /usr/lib/p2c/system.m2 analogous declarations    for Modula-2
  1405.       /usr/lib/p2c/*.imp     interface text    for standard modules
  1406.       /usr/include/p2c/p2c.h header    file for translated programs
  1407.       /usr/lib/libp2c.a     run-time library
  1408.  
  1409.      AUTHOR
  1410.       Dave Gillespie, daveg@csvax.cs.caltech.edu.
  1411.  
  1412.       Many thanks to William Bader,    Steven Levi, Rick Koshi, Eric
  1413.       Raymond, Magne Haveraaen, Dirk Grunwald, David Barto,    Paul
  1414.       Fisher, Tom Schneider, and others whose suggestions and bug
  1415.       reports have helped improve p2c in countless ways.
  1416.  
  1417.  
  1418.  
  1419.  
  1420.  
  1421.  
  1422.  
  1423.  
  1424.  
  1425.  
  1426.  
  1427.  
  1428.  
  1429.  
  1430.  
  1431.  
  1432.  
  1433.  
  1434.  
  1435.  
  1436.  
  1437.  
  1438.  
  1439.  
  1440.  
  1441.  
  1442.  
  1443.  
  1444.  
  1445.  
  1446.  
  1447.  
  1448.  
  1449.                   - 22 - Formatted:  February 28, 1991
  1450.  
  1451.  
  1452.